package com.jdk21.learning;

/**
 * @program: jdk21-learning
 * @description:
 * @author: YuKai Fan
 * @create: 2024/8/10 23:03
 **/
public class RecordPatternsDemo {
    record Person(String name, int age) {}

    public static void main(String[] args) {
        Person person = new Person("YK", 28);
        if (person instanceof Person p) {
            System.out.println(p.name);
            System.out.println(p.age);
        }
    }

    record Point(int x, int y) {}

    static void printSumOld(Object obj) {
        if (obj instanceof Point p) {
            int x = p.x();
            int y = p.y();
            System.out.println(x + y);
        }
    }

    static void printSumNew(Object obj) {
        if (obj instanceof Point(int x, int y)) {
            System.out.println(x + y);
        }
    }
}
